package com.BXuan.字节每日一题;

import java.util.Stack;

/**
 * 10.19 - 232.用栈实现队列
 */
class MyQueue {
    // 初始化
    /*
        栈 先进先出、队列 先进后出
    */
    Stack<Integer> stack1;
    Stack<Integer> stack2;

    public MyQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int x) {
        while (!stack2.empty()){
            int temp = stack2.pop();
            stack1.push(temp);
        }
        stack1.push(x);
    }
    // 移除对象
    public int pop() {
        while (!stack1.empty()){
            int temp = stack1.pop();
            stack2.push(temp);
        }
        return stack2.pop();
    }
    // 获取但不移除
    public int peek() {
        while (!stack1.empty()){
            stack2.push(stack1.pop());
        }
        return stack2.peek();
    }

    public boolean empty() {
        return (stack1.empty()&&stack2.empty());
    }
}
